package com.kdg.thread.consurrenttest.threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池
 * @author kdg
 * @description:
 * @date 2018/5/15.
 */
public class ThreadPools{

    private static final int COOL_POOL_SIZE = 10;

    public static void main(String[] args) {
//        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
        ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(COOL_POOL_SIZE);
        executorService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                    System.out.println(System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },0,2,TimeUnit.SECONDS);
    }
}
